package com.timothy.junk.adapter;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
import com.timothy.junk.R;
import com.timothy.junk.common.bean.JunkNotify;

import java.util.List;

public class JunkNotifyAdaptor extends BaseAdapter {
	private Context mContext;
	private SharedPreferences sp;
	private List<JunkNotify> listItems;
	private LayoutInflater mInflater;

	static class ViewHolder{
		public TextView junkIndex;
        public TextView junkName;
		public EditText notfiyInterval;
		public ToggleButton ifNotify;
	}

	public JunkNotifyAdaptor(Context context, List<JunkNotify> data,SharedPreferences sp) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context); 
		this.listItems = data;
	}

	
	@Override
	public int getCount() {
		return listItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;  
        if (convertView == null){  
            holder = new ViewHolder();  
            convertView = mInflater.inflate(R.layout.junk_notify_list_item, null);
            
            holder.junkIndex = (TextView) convertView.findViewById(R.id.junkIndex);
			holder.junkName = (TextView) convertView.findViewById(R.id.junkName);
			holder.notfiyInterval = (EditText) convertView.findViewById(R.id.notfiyInterval);
			holder.ifNotify = (ToggleButton) convertView.findViewById(R.id.ifNotify);
			
            convertView.setTag(holder);  
        }else {  
            holder = (ViewHolder) convertView.getTag();  
        }

        JunkNotify bean = listItems.get(position);
		holder.junkIndex.setText(String.valueOf(bean.getId()));
		holder.junkName.setText(bean.getName());
		holder.notfiyInterval.setText(String.valueOf(bean.getInterval()));
		if(bean.isIfNotify()){
			holder.ifNotify.setChecked(true);
		}else{
			holder.ifNotify.setChecked(false);
		}

        return convertView; 
        
	}

}
